package com.lagou.interceptor;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lagou.pojo.User;
import com.lagou.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Arrays;
import java.util.Map;

/**
 * @author lbq
 * @version 1.0
 * @date 2021/1/27 21:20
 */
@Component
public class MyInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        String user = (String) session.getAttribute("loginUser");
        if ("jack".equals(user)) {
            return true;
        }
        Map<String, String[]> parameterMap = request.getParameterMap();
        for (String key : parameterMap.keySet()) {
            System.out.println(key + " ; " + Arrays.toString(parameterMap.get(key)));
        }
        System.out.println("当前用户没登陆,跳转");
        response.sendRedirect(request.getContextPath() + "/login/loginSystem");
        return false;
    }
}
